package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Form4;
 
 
public class Form4DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Form4DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Form4 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Form4> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Form4> list = session.selectList("Form4.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form4 instance from the database*/
    public Form4 selectById(int liquidation_form_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form4 form4 = (Form4) session.selectOne("Form4.getById",liquidation_form_no);
            return form4;
        } finally {
            session.close();
        }
    }
    
    /**Returns a Form4 instance from the database
    public Form4 getAllPending(String status){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form4 form4 = (Form4) session.selectOne("Form4.getAllPending", status);
            return form4;
        } finally {
            session.close();
        }
    }*/
 
    /**Updates an instance of Form4 in the database*/
    public void update(Form4 form4){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form4.update", form4);
            session.commit();
        } finally {
            session.close();
        }
    }
    
    /**Updates the status of Form4 in the database
    public void updateStatus(int payroll_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form4.updateStatus", payroll_no);
            session.commit();
        } finally {
            session.close();
        }
    }*/
 
    /** Insert an instance of Form4 into the database*/
    public void insert(Form4 form4){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Form4.insert", form4);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Form4 from the database*/
    public void delete(int liquidation_form_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Form4.deleteById", liquidation_form_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}